//获取当前时间
var myDate = new Date();
var myYear = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
var myMonth = myDate.getMonth()+1; //获取当前月份(0-11,0代表1月)
var myToday = myDate.getDate(); //获取当前日(1-31)
var myDay = myDate.getDay(); //获取当前星期X(0-6,0代表星期天)
var myHour = myDate.getHours(); //获取当前小时数(0-23)
var myMinute = myDate.getMinutes(); //获取当前分钟数(0-59)
var mySecond = myDate.getSeconds(); //获取当前秒数(0-59)
var newTime = myYear+'-'+myMonth+'-'+myToday+' '+myHour+':'+myMinute+':'+mySecond;
layui.use(['jquery','layer','form','table','laydate','upload'],function(){
    var $ = layui.$,layer = layui.layer,form = layui.form,table = layui.table,laydate = layui.laydate,upload = layui.upload;
    //普同检索 22/1/12
    form.on('submit(sub)',function(data){
        $.ajax({
            url: '/user/getShutDownUsers'
            ,data: {
                'account': data.field.account
                ,'reason': data.field.reason
                ,'days': data.field.days
            }
            ,dataType: 'json'
            ,success:function(data){
                tableRender(data.data);
            }
        });
    });
    //获取已封禁用户 22/1/12 赵
    getUsers();
    function getUsers(userId){
        $.ajax({
            url: '/user/getShutDownUsers'
            ,data: {'userId': userId}
            ,dataType: 'json'
            ,success:function(data){
                //渲染表格
                tableRender(data.data);
            }
        });
    }
    //渲染表格 22/1/12 赵
    tableRender = function tableRender(data){
        table.render({
            elem: '#layuiTbale'
            ,data: data
            ,toolbar: '#toolutil'
            ,page: {
                layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']//自定义分页布局
                ,limits:[10,15,20]
                ,first: true
                ,last: true
            }
            ,limit: 10
            ,cols: [[
                {checkbox: true}
                ,{type: 'numbers',title: '序号',align: 'center'}
                ,{field: 'userId',title: '用户编号',align: 'center'}
                ,{field: 'nickname',title: '用户昵称',align: 'center'}
                ,{field: 'startDate',title: '封停时间',align: 'center'}
                ,{field: 'endDate',title: '解封时间',align: 'center'}
                ,{field: 'reason',title: '封停原因',align: 'center'}
                ,{field: 'days',title: '封停天数',align: 'center'}
                ,{title: '操作',align: 'center',templet:function(data){
                        return '<a onclick="unseal('+data.userId+')" style="color: #009688;">解封</a> '
                    }}
            ]]
        });
    }

    //解封 22/1/12 赵
    unseal = function unseal(userId){
        layer.open({
            title: '解封用户'
            ,content: '是否手动解封用户？'
            ,area: ['200px','200px']
            ,btn: ['确定','取消']
            ,yes:function(index){
                $.ajax({
                    url: '/user/unsealUser'
                    ,data: {'userId': userId,'status': 2}
                    ,dataType: 'json'
                    ,success:function(data){
                        //添加解封记录
                        $.ajax({
                            url: '/user/addUnsealRecord'
                            ,data: {
                                'userId': userId
                                ,'type': 1
                                ,'unsealDate': newTime
                                ,'remarks': '手动解除封禁'
                            }
                            ,dataType: 'json'
                            ,success:function(data){
                                layer.close(index);
                                getUsers();
                                layer.msg('已解封');
                            }
                        })
                    }
                });
            }
            ,btn2:function(index){
                layer.close(index);
            }
        });
    }
    /*
            String  account
            ,String nickname
            ,String idCard
            ,String phone
            ,String startDate
            ,String endDate
            ,String reason
            ,Long days
            ,Integer userId
    */


    //高级检索 22/1/12 赵
    advancedRetrieval = function advancedRetrieval(){
        layer.open({
            type: 2
            ,title: '高级检索'
            ,content: 'popup/shutDown-list-advancedRetrieval.html'
            ,area: ['650px','330px']
        });
    }


    //刷新 22/1/12 赵
    refresh = function refresh(){
        location.reload();
    }

    //返回
});
//返回首页
function backOff(){
    parent.jumpSystemHome();
}